package com.iswoak.netctoss.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import com.iswoak.netctoss.dao.AdminInfoDao;
import com.iswoak.netctoss.util.DBUtil;

public class AdminInfoDaoImpl implements AdminInfoDao {

	public List<String> findAllMouduleByAdminCode(String adminCode) {
		Connection conn = DBUtil.getConnection();
		PreparedStatement ps = null;
		List<String> list = new ArrayList<String>();
		String sql = "select distinct mi.name from admin_info ai " + 
				"left join admin_role ar on ai.admin_id = ar.admin_id " + 
				"LEFT JOIN role_module rm on ar.role_id = rm.role_id " + 
				"LEFT JOIN module_info mi on rm.module_id = mi.module_id " + 
				"where ai.admin_code = ? ";	
		//创建ps对象
		try {
			ps = conn.prepareStatement(sql);
			//设置参数
			ps.setString(1, adminCode);
			System.out.println(sql);
			ResultSet rs = ps.executeQuery();
			while (rs.next()) {				
				list.add(rs.getString("name"));
			}
			rs.close();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			DBUtil.closeConnectionAndPreparedStatement(conn, ps);
		}
		return list;	
	}

}
